<%@page import="Filter.DAO"%>
<%@page import="java.util.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    String num ="0";    //num 是由 pagenum(使用者輸入)  決定要跳過多少筆資料(num=pagenum*3)
    String y = "3";  //每頁幾筆資料
    String sql="select * from product";
    DAO db =new DAO(); 
    if (request.getParameter("pagenum")!=null && request.getParameter("pagenum")!="")
    {
      num = Integer.toString(Integer.parseInt(request.getParameter("pagenum"))*Integer.parseInt(y));      
    }
    ArrayList<HashMap> rslist= db.query2(sql, new String[]{}, num , y); 
    int fin=db.GGININ()/Integer.parseInt(y);  //gginin是資料筆數　　fin為最大頁數
    if(db.GGININ()%Integer.parseInt(y)==0)
        fin--;
    HashMap map;
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <style>
            #size{
                width:800px;
                height:600px;
            }
            #listbox{
                border-style: solid;
                border-width: 2px;             
            }
            body{background-color:#EEE;}
            .BOX{width: available;
                 height: 300px ;
                
                
                 position: absolute;
                 left: 25%;
                 top:  30%;
                 
                 margin-top:  -150px;
                 margin-left:  -150px;} 
           
        </style>
    </head>
     
    <body>
        <div class="BOX" id="size">           
            <table id="listbox"> <!--商品顯示頁面-->
                <tr>
            <%   
                  for(int i =0;i<rslist.size();i++)
                  {
                      map =rslist.get(i); 
                      int x = Integer.parseInt((String)map.get("product_id"))-1;
                      out.println("<td><a href='infor.jsp?product_id="+x+"'><img style='width:320px ;height:240px; 'src='"
                              +map.get("img_url")+"'/></a></td>");                   
                  }
            %>             
                </tr><tr>
            <%
                  for(int i =0;i<rslist.size();i++)
                  {
                      map =rslist.get(i);  
                      int x = Integer.parseInt((String)map.get("product_id"))-1;
                    out.println("<td><a href='infor.jsp?product_id="+x+"'>"
                              +map.get("product_name")+"</a></td>");  }      
            %>  
                </tr><tr>
            <%
                  for(int i =0;i<rslist.size();i++)
                  {
                      map =rslist.get(i);                  
                      out.println("<td>價格:"+map.get("product_price")+"<br>庫存:"+map.get("product_stock")+"</td>");
                  }
            %>
                </tr>            
             </table>                 
                <form action="ProductList.jsp" >
                <table style="margin-left:30%;">
                    <tr>    
                    <td>
                <!--上一頁-->
                <%
                    if (!"0".equals(num)){ 
                %>   
                <a href="ProductList.jsp?pagenum=<%=((Integer.parseInt(num)/Integer.parseInt(y))-1)%>">
                    <img style="width:25px; height:25px;" src="http://etc-mysitemyway.s3.amazonaws.com/icons/legacy-previews/icons/green-jelly-icons-arrows/008553-green-jelly-icon-arrows-triangle-solid-left.png"/></a>
                <%
                    }
                    else{
                    %>
                    <img style="width:25px; height:25px;" src="http://etc-mysitemyway.s3.amazonaws.com/icons/legacy-previews/icons/green-jelly-icons-arrows/008553-green-jelly-icon-arrows-triangle-solid-left.png"/>
                    <%
                    }
                %>
                </td><td>
                <input type="text" name="pagenum" autofocus/>
                </td><td>
                <input type="submit" name="sendpage" value="前往"/>
                </td><td>
                <!--下一頁-->
                <%                    
                    if((Integer.parseInt(num)/Integer.parseInt(y)) < fin){ 
                %>
                    <a href="ProductList.jsp?pagenum=<%=(Integer.parseInt(num)/Integer.parseInt(y))+1%>">
                    <img style="width:25px; height:25px;" src="http://etc-mysitemyway.s3.amazonaws.com/icons/legacy-previews/icons/green-jelly-icons-arrows/008554-green-jelly-icon-arrows-triangle-solid-right.png"/>                
                    </a>
                <%
                    }
                %>         
               </td> </tr> </table>   </form>   
                <div><input type="button" value="<-Back" onclick="javascript:history.go(-1);"></div>
        </div>
    </body>
</html>
